#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <math.h>

#define HDX019_NODE "/dev/ctrl"

unsigned char learn_cmd[] = {0x30, 0x20, 0x50, 0x00};
#define MAX_BUFFER_COUNT 256
unsigned char buff[MAX_BUFFER_COUNT];


unsigned char carrier_38K[] ={0x30,0x30,0x60};
unsigned char carrier_56K[] ={0x30,0x40,0x70};
unsigned char carrier_30K[] ={0x30,0x31,0x61};
unsigned char carrier_33K[] ={0x30,0x32,0x62};
unsigned char carrier_42K[] ={0x30,0x33,0x63};
unsigned char carrier_70K[] ={0x30,0x34,0x64};
unsigned char carrier_24K[] ={0x30,0x35,0x65};
unsigned char carrier_80K[] ={0x30,0x36,0x66};


int main(int ac ,char *av)
{

	FILE * fp;
	int i = 0;
	int n = 0, ret=0;
	if(NULL==(fp=fopen(HDX019_NODE, "rw"))){
		fprintf(stderr, "open %s fail: %s\n", HDX019_NODE, strerror(errno));
		return -ENODEV;
	}
	n = sizeof(learn_cmd) / sizeof(learn_cmd[0]);
	ret = fwrite(learn_cmd, 1, n, fp);
	printf("fwrite %d get %d\n", n, ret);
	rewind(fp);
	printf("Learn: wait 2 second\n");
	sleep(2);
	ret = fread(buff, 1, MAX_BUFFER_COUNT, fp);
	printf("fread %d\n", ret);

	for(i=0; i < ret; i++){
		printf("%02x ", buff[i]);
		if(i %16 == 0){
			printf("\n");
		}
	}
	printf("\n");
	fclose(fp);
	return 0;
}